
** set path
// gl path ""

** open log
cap log close
log using "$path/table_a9.log", replace

** Presidential results without county pop weights

use "$path/foreclosures_analysis.dta", clear

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate foreclosure_inc, a(fips sy) cluster(fips)
local b1 = _b[foreclosure_rate]
local se1 = _se[foreclosure_rate]
local bint1 = _b[foreclosure_inc]
local seint1 = _se[foreclosure_inc]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate foreclosure_inc, a(fips popyear) cluster(fips)
local b2 = _b[foreclosure_rate]
local se2 = _se[foreclosure_rate]
local bint2 = _b[foreclosure_inc]
local seint2 = _se[foreclosure_inc]
local n2 = e(N)
local nclust2 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate foreclosure_inc, a(i.fips##c.year sy) cluster(fips)
local b3 = _b[foreclosure_rate]
local se3 = _se[foreclosure_rate]
local bint3 = _b[foreclosure_inc]
local seint3 = _se[foreclosure_inc]
local n3 = e(N)
local nclust3 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate foreclosure_inc, a(i.fips##c.year popyear) cluster(fips)
local b4 = _b[foreclosure_rate]
local se4 = _se[foreclosure_rate]
local bint4 = _b[foreclosure_inc]
local seint4 = _se[foreclosure_inc]
local n4 = e(N)
local nclust4 = e(N_clust)

log close

quietly {
	cap log close
	set linesize 255
	log using "$path/foreclosure_main_no_weights.tex", text replace
	
	noisily dis "\begin{table}[h]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Housing Foreclosures on Presidential Elections, County Level, 2004--2016.}"
	noisily dis "\label{tab:main_no_weights}}"
	noisily dis "\begin{tabular}{lcccc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{4}{c}{Dem Pres Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2) & (3) & (4)  \\"
	noisily dis "\midrule"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1' " & " %4.2f `b2' " & " %4.2f `b3' " & " %4.2f `b4'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ") & (" %4.2f `se3' ") & (" %4.2f `se4' ") \medskip \\"
	noisily dis "Foreclosures $ \times $ Inc Party &  " %4.2f `bint1' " & " %4.2f `bint2' " & " %4.2f `bint3' " & " %4.2f `bint4' "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ") & (" %4.2f `seint3' ") & (" %4.2f `seint4' ")  \medskip \\"

	noisily dis " N & " %4.0fc `n1' " & " %4.0fc `n2' " & " %4.0fc `n3' " & " %4.0fc `n4' " \\ "
	noisily dis " \# Counties & "  %4.0fc `nclust1' " & " %4.0fc `nclust2' " & " %4.0fc `nclust3' " & " %4.0fc `nclust4'  " \\ "
	noisily dis "County Fixed Effects & Y & Y & Y & Y  \\"
	noisily dis "State-Year Fixed Effects & Y & N & Y & N  \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y & N & Y \\"
	noisily dis "County Linear Trends & N & N & Y & Y \\"
	noisily dis " Population Weights & N & N & N & N \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{5}{p{.65\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure. "
	noisily dis "Inc Party is 1 for Dem, -1 for Rep.  Main effect for Inc Party is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
